#include "cubedata.h"
#include "loadthreadshared.h"
CubeDataRef::CubeDataRef(CubeData* f) :
	_cube{ f }
{
}
CubeDataRef::CubeDataRef(const CubeDataRef& r) :
	_cube{ r._cube }
{
	if (_cube) {
		_cube->lts->ref(_cube);
	}
}
CubeDataRef& CubeDataRef::operator=(const CubeDataRef& r) {
	if (_cube) {
		_cube->lts->unref(_cube);
	}
	_cube = r._cube;
	if (_cube) {
		_cube->lts->ref(_cube);
	}
	return *this;
}
void CubeDataRef::release() {
	if (_cube) {
		_cube->lts->unref(_cube);
		_cube = nullptr;
	}
}
CubeType CubeDataRef::type() const {
	return _cube->type;
}
int64_t CubeDataRef::width() const {
	return _cube->id.nx*_cube->xsize;
}
int64_t CubeDataRef::height() const {
	return _cube->id.ny*_cube->ysize;
}
int64_t CubeDataRef::depth() const {
	return _cube->id.nz*_cube->zsize;
}
int64_t CubeDataRef::widthAdj() const {
	return _cube->widthAdj;
}
int64_t CubeDataRef::heightAdj() const {
	return _cube->heightAdj;
}
int64_t CubeDataRef::depthAdj() const {
	return _cube->depthAdj;
}
int64_t CubeDataRef::size(int dir) const {
	switch (dir) {
	case 0:
		return width();
	case 1:
		return height();
	case 2:
		return depth();
	}
	return 0;
}
const char* CubeDataRef::data() const {
	return _cube->data;
}
const CubeId& CubeDataRef::cubeId() const {
	return _cube->id;
}